package cn.com.czpb.client.module.personal.acticity;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import cn.com.czpb.client.R;
import cn.com.czpb.client.api.InterfaceJsonfile;
import cn.com.czpb.client.app.MToolBarActivity;
import cn.com.czpb.client.module.personal.fragment.FindbackpwFragment;
import cn.com.czpb.client.module.personal.fragment.LoginFragment;
import cn.com.czpb.client.module.personal.fragment.RegisterFragment;
import cn.com.czpb.client.utils.ActionbarUtils;

public class LoginActivity extends MToolBarActivity {
    private LoginFragment loginFragment;
    private RegisterFragment registerFragment;
    private FindbackpwFragment findbackpwFragment;

    private FragmentManager fm;
    private Fragment currentFm;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //状态栏字体颜色设置成深色
        ActionbarUtils.setMeizuStatusBarDarkIcon(activity, true);
        ActionbarUtils.setMiuiStatusBarDarkMode(activity, true);

//        setToolBarVisiable(false);

        Intent intent = getIntent();


    }

    @Override
    protected void initView() {
        fm = getSupportFragmentManager();
        loginFragment = new LoginFragment();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.frame_login_activity, loginFragment);
        ft.commitAllowingStateLoss();
        currentFm = loginFragment;
        super.initView();
    }

    @Override
    protected int setLayoutId() {
        return R.layout.activity_login;
    }


//    //    @Override
//    public int setMyContentView() {
//        return R.layout.activity_login;
//    }


    public void toFindbackpwdFm() {
        FragmentTransaction ft = fm.beginTransaction();
        ft.setCustomAnimations(R.anim.push_left_in
                , R.anim.push_alpha_in
                , R.anim.push_alpha_out
                , R.anim.push_left_out);
        Bundle args = new Bundle();
        args.putInt(InterfaceJsonfile.PWDTYPE, 1);
        findbackpwFragment = new FindbackpwFragment();
        findbackpwFragment.setArguments(args);
        ft.add(R.id.frame_login_activity, findbackpwFragment).hide(currentFm);
        ft.addToBackStack(null);
        ft.commit();
        currentFm = findbackpwFragment;
    }

    @Override
    protected void onRestart() {
        initView();
        super.onRestart();
    }

    public void toRegisterFm() {
        FragmentTransaction ft = fm.beginTransaction();
        ft.setCustomAnimations(R.anim.push_left_in
                , R.anim.push_alpha_in
                , R.anim.push_alpha_out
                , R.anim.push_left_out);
        Bundle args = new Bundle();
        args.putInt(InterfaceJsonfile.PWDTYPE, 1);
        registerFragment = new RegisterFragment();
        registerFragment.setArguments(args);
        ft.add(R.id.frame_login_activity, registerFragment).hide(currentFm);
        ft.addToBackStack(null);
        ft.commit();
        currentFm = registerFragment;
    }
    public void toLoginFm() {
        FragmentTransaction ft = fm.beginTransaction();
        ft.setCustomAnimations(R.anim.push_left_out
                , R.anim.push_alpha_out
                , R.anim.push_alpha_in
                , R.anim.push_left_in);
        Bundle args = new Bundle();
        args.putInt(InterfaceJsonfile.PWDTYPE, 1);
        loginFragment = new LoginFragment();

        ft.add(R.id.frame_login_activity, loginFragment).hide(currentFm);
        ft.addToBackStack(null);
        ft.commit();
        currentFm = loginFragment;
    }

    public void Loginfinish() {
        activity.finish();
    }

}
